import util.TreeNode;

import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;

/**
 * Created by Vince on 2017/8/16.
 */
public class Solution {
    public ArrayList<Integer> PrintFromTopToBottom(TreeNode root) {
        ArrayList<Integer> result = new ArrayList<Integer>();
        Deque<TreeNode> deque = new LinkedList<TreeNode>();

        if (root == null) return result;
        deque.add(root);
        while (!deque.isEmpty()){
            TreeNode treeNode = deque.pop();
            result.add(treeNode.val);
            if (treeNode.left != null) deque.add(treeNode.left);
            if (treeNode.right != null) deque.add(treeNode.right);
        }
        return result;
    }
}
